package com.xxg.renrenuser.controller;

import com.xxg.renrencommon.domain.result.BaseResult;
import com.xxg.renrencommon.domain.result.PageInfoResult;
import com.xxg.renrenuser.dao.bean.UserCashOutInfo;
import com.xxg.renrenuser.domain.query.CashOutQuery;
import com.xxg.renrenuser.domain.query.GetCashOutListQuery;
import com.xxg.renrenuser.domain.query.SetApplyStatusQuery;
import com.xxg.renrenuser.domain.result.CountBenefitResult;
import com.xxg.renrenuser.domain.result.GetByStatusResult;
import com.xxg.renrenuser.service.UserSpreadBenefitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 收益管理
 *
 * @author szj
 * @date 2021/12/21
 */
@Api(tags = "收益管理接口")
@RestController
@RequestMapping("/benefit")
@AllArgsConstructor
public class UserSpreadBenefitController {
    private final UserSpreadBenefitService userSpreadBenefitService;

    @ApiOperation("查看收益统计")
    @RequestMapping(value = "countBenefit", method = RequestMethod.GET)
    public BaseResult<CountBenefitResult> countBenefit(HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return userSpreadBenefitService.countBenefit(userId);
    }

    @ApiOperation("根据状态查看收益订单记录")
    @RequestMapping(value = "getByStatus", method = RequestMethod.GET)
    @ApiImplicitParams({@ApiImplicitParam(name = "status", value = "收益状态 0-待结算 1-已结算（可提现） 2-已提现", required = true, dataType = "Integer", paramType = "query")})
    public BaseResult<List<GetByStatusResult>> getByStatus(@RequestParam("status") Integer status, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return userSpreadBenefitService.getByStatus(status, userId);
    }

    @ApiOperation("提现")
    @RequestMapping(value = "cashOut", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "提现信息", required = true, dataType = "CashOutQuery")})
    public BaseResult<Void> cashOut(@RequestBody @Validated CashOutQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return userSpreadBenefitService.cashOut(userId, query);
    }

    @ApiOperation("后台接口，分页获取客户的提现申请列表")
    @RequestMapping(value = "getApplyList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "分页参数", required = true, dataType = "GetCashOutListQuery")})
    public BaseResult<PageInfoResult<UserCashOutInfo>> getApplyList(@RequestBody @Validated GetCashOutListQuery query) {
        return userSpreadBenefitService.getApplyList(query);
    }

    @ApiOperation("后台接口，批量设置提现申请列表已处理状态")
    @RequestMapping(value = "setApplyStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "setApplyStatusQuery", value = "设置提现申请状态参数", required = true, dataType = "SetApplyStatusQuery")})
    public BaseResult<Void> setApplyStatus(@RequestBody @Validated SetApplyStatusQuery setApplyStatusQuery) {
        return userSpreadBenefitService.setApplyStatus(setApplyStatusQuery.getIds());
    }
}
